<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>山东营销风云榜</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../css/part/tabHead.css">
    <link rel="stylesheet" href="../../../css/part/mini.css">
</head>

<body>

<div id="app">
    <div id="tableHead">
        <img src="../../../img/part/newAdd/branch3Month.png" id="branchHead" align="center">
        <a href="../../portal/navigationYX.html"><img src="../../../img/portal/min.png" id="miniImg"></a>
        <table width="100%">
            <tr >
                <thead>
                <th width="10%">NO</th>
                <th width="16%">机构</th>
                <th width="14%">三月新人数</th>
                <th width="15%">三月新人实动</th>
                <th width="15%">首月实动率</th>
                <th width="15%">次月实动率</th>
                <th width="15%">次次月实动率</th>
                </thead>
            </tr>
        </table>
    </div>
    <div id="midDiv"></div>
    <div class="tableBody">
        <table id="tab" width="100%">
            <tbody id="tbody">
            </tbody>
        </table>
    </div>
</div>
</body>
<script src="../../../js/vue.js"></script>
<script src="../../../js/axios.js"></script>
<script src="../../../js/head.js"></script>
<script src="../../../js/jquery-3.2.1.min.js"></script>
<script src="../../../js/share.js"></script>


<script>
    window.onload = function () {
        new Vue({
            el: '#app',
            data() {
                return {
                    //中支名称
                    branchsName: '',

                    branchThreeMon: 0,
                    branchThreeMonAct: 0,

                    //首月
                    branchNowMonNum: 0,
                    branchNowMonAgent: 0,
                    branchOneMonYield: 0,
                    //次月
                    branchTwoMonNum: 0,
                    branchTwoMonAgent: 0,
                    branchTwoMonYield: 0,
                    //次次月
                    branchThreeMonNum: 0,
                    branchThreeMonAgent: 0,
                    branchThreeMonYield: 0,
                    pojo: {},
                    divHeight: 0,

                }
            },
            created() {
                this.getBranch3Month();
            },
            methods: {

                //获取各中支的数据
                getBranch3Month() {
                    document.getElementById("midDiv").style.height = window.getComputedStyle(document.getElementById("tableHead")).getPropertyValue("height");
                    setTimeout(() => {
                        axios.get(`/newAdd/getBranch3Month`).then(response => {
                            this.pojo = response.data;
                            var str = "";//定义用于拼接的字符串
                            for (var i = 0; i < this.pojo.length; i++) {

                                this.branchThreeMon = this.branchThreeMon + this.pojo[i].branchThreeMon;
                                this.branchThreeMonAct = this.branchThreeMonAct + this.pojo[i].branchThreeMonAct;

                                this.branchNowMonNum = this.branchNowMonNum + this.pojo[i].branchNowMonNum;
                                this.branchNowMonAgent = this.branchNowMonAgent + this.pojo[i].branchNowMonAgent;

                                this.branchTwoMonNum = this.branchTwoMonNum + this.pojo[i].branchTwoMonNum;
                                this.branchTwoMonAgent = this.branchTwoMonAgent + this.pojo[i].branchTwoMonAgent;

                                this.branchThreeMonNum = this.branchThreeMonNum + this.pojo[i].branchThreeMonNum;
                                this.branchThreeMonAgent = this.branchThreeMonAgent + this.pojo[i].branchThreeMonAgent;
                                //拼接表格的行和列
                                str = "<tr><td width=\"10%\">" + (i + 1) + "</td>" +
                                    "<td width=\"16%\">" + this.pojo[i].branchsName + "</td>" +
                                    "<td width=\"14%\">" + this.pojo[i].branchThreeMon + "</td>" +
                                    "<td width=\"15%\">" + this.pojo[i].branchThreeMonAct + "</td>" +
                                    "<td width=\"15%\">" + this.dataHandle(this.pojo[i].branchOneMonYield) + "</td>" +
                                    "<td width=\"15%\">" + this.dataHandle(this.pojo[i].branchTwoMonYield) + "</td>" +
                                    "<td width=\"15%\">" + this.dataHandle(this.pojo[i].branchThreeMonYield) + "</td></tr>";
                                //追加到table中
                                $("#tbody").append(str);
                            }
                            str = "<tr><th colspan=\"2\" style=\"font-weight: bolder\">" + '合计:' + "</th>" +
                                "<th width=\"14%\">" + this.branchThreeMon + "</th>" +
                                "<th width=\"15%\">" + this.branchThreeMonAct + "</th>" +
                                "<th width=\"14%\">" + this.dataHandle(this.doubleHandle(this.branchNowMonNum, this.branchNowMonAgent)) + "</th>" +
                                "<th width=\"14%\">" + this.dataHandle(this.doubleHandle(this.branchTwoMonNum, this.branchTwoMonAgent)) + "</th>" +
                                "<th width=\"15%\">" + this.dataHandle(this.doubleHandle(this.branchThreeMonNum, this.branchThreeMonAgent)) + "</th></tr>";
                            $("#tbody").append(str);

                        })
                    }, 200)
                },
                //数据处理
                dataHandle(_this) {
                    var data = _this + "";
                    if (data.indexOf(".") != -1) {
                        return data + '%'
                    }
                    if (data == -9999) {
                        return '-'
                    }
                    return data + ".0" + '%';
                },
                //处理两数相除
                doubleHandle(a, b) {
                    if (b == 0) {
                        return -9999;
                    } else {
                        return Math.round(a * 1000 / b) / 10;
                    }
                }
            }
        })
    }
</script>

</html>